<?php
 include_once './lib/fun.php';
 date_default_timezone_set('ASIA/ShangHai');
 $login = checkLogin();
 if ($login) {
     $user = $_SESSION['user'];
     $id = isset($_GET['id']) && is_numeric($_GET['id'])?intval($_GET['id']):'';
     if ($id) {
         mysqlInit('127.0.0.1', 'root', 'root', 'mall');
         $sql = "SELECT goods.* ,user.username FROM  `mall_goods` AS goods JOIN  `mall_user` AS user ON goods.user_id = user.id WHERE goods.id = '{$id}'";
         $res = mysql_query($sql);
         $goods = mysql_fetch_assoc($res);
         if ($goods) {
             unset($sql,$res);
             $sql = "UPDATE `mall_goods` SET `view`=`view`+1 WHERE `id`={$id}";
             $res = mysql_query($sql);
             $row = mysql_affected_rows();
             if ($row == 0) {
                 toMsgPage(2, mysql_error(), 'index.php');
             }
         } else {
             toMsgPage(2, '没有找到该商品信息', 'index.php');
         }
     } else {
         toMsgPage(2, '非法参数', 'index.php');
     }
 } else {
     toMsgPage(2, '请先登录再进行查看', 'login.php');
 }
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>M-GALLARY|<?php echo $goods['name'] ?></title>
    <link rel="stylesheet" type="text/css" href="./static/css/common.css" />
    <link rel="stylesheet" type="text/css" href="./static/css/detail.css" />
</head>
<body class="bgf8">
<div class="header">
    <div class="logo f1">
        <img src="./static/image/logo.png">
    </div>
    <div class="auth fr">
        <ul>
            <li><a href="#"><?php echo $user['username'] ?></a></li>
            <li><a href="./logout.php">退出</a></li>
        </ul>
    </div>
</div>
<div class="content">
    <div class="section" style="margin-top:20px;">
        <div class="width1200">
            <div class="fl"><img src="<?php echo '.'.$goods['pic'] ?>" width="720px" height="432px"/></div>
            <div class="fl sec_intru_bg">
                <dl>
                    <dt><?php echo $goods['name'] ?></dt>
                    <dd>
                        <p>发布人：<span><?php echo $goods['username'] ?></span></p>
                        <p>发布时间：<span><?php echo date('Y年m月d日', $goods['create_time']) ?></span></p>
                        <p>修改时间：<span><?php echo date('Y年m月d日', $goods['update_time']) ?></span></p>
                        <p>浏览次数：<span><?php echo $goods['view'] ?></span></p>
                    </dd>
                </dl>
                <ul>
                    <li>售价：<br/><span class="price"><?php echo $goods['price'] ?></span>元</li>
                    <li class="btn"><a href="javascript:;" class="btn btn-bg-red" style="margin-left:38px;">立即购买</a></li>
                    <li class="btn"><a href="javascript:;" class="btn btn-sm-white" style="margin-left:8px;">收藏</a></li>
                </ul>
            </div>
        </div>
    </div>
    <div class="secion_words">
        <div class="width1200">
            <div class="secion_wordsCon">
            <?php echo $goods['content'] ?>
            </div>
        </div>
    </div>
</div>
<div class="footer">
    <p><span>M-GALLARY</span>©2017 POWERED BY IMOOC.INC</p>
</div>
</div>
</body>
</html>

